<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<!-- <script type="text/javascript" src="laypage/laypage.js"></script> -->
<link rel="stylesheet" type="text/css" href="css\layui.css"> 
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css\bootstrap.min.css">
</head>
<body>
 <script type="text/javascript">
function addOrder(ob){
	 var ingName= $(ob).parent().siblings("td").eq(1).text();
	 var ingImage= $(ob).parent().siblings("td").eq(2).text();
	 var ingPrice= $(ob).parent().siblings("td").eq(3).text();
	 var ingDetail= $(ob).parent().siblings("td").eq(4).text();
	  var ingId=$(ob).siblings("input").eq(0).val();
	  $("#ingName").val(ingName);
	  $("#ingImage").val(ingImage);
	  $("#ingPrice").val(ingPrice);
	  $("#ingDetail").val(ingDetail);
	  $("#ingId").val(ingId);
	  alert(ingId);
}
//è·åæ¨¡ææ¡æ°æ®
function add(){	
	 var ingId=$("#ingId").val();    
	  var ingName=$("#ingName").val();
	  var ingPrice=$("#ingPrice").val();
	  var ingDetail=$("#ingDetail").val();
	  var address=$("#address").val();
	  var rname=$("#rname").val();
	  var phone=$("#phone").val();
	  var ingImage=$("#ingImage").val();
	  var ingId=$("#ingId").val();
	  var u_id=$("#u_id").val();
	  $.ajax({
		  type: "post",
	        url: "addInorder",
	        data: {'ing_id':ingId,'ingName':ingName,'ingPrice':ingPrice,'ingDetail':ingDetail,'address':address,'rname':rname,'phone':phone,'ingImage':ingImage,'u_id':u_id},
	        dataType: 'json',
	        async:'true',
		  success: function(result){			 			  
		  }		  		  
	  })	  

}

</script>

<script type="text/javascript">
/*  
 * ====================================================================================================================================================
 */
  function updateData(obj){		 
	  var ingName= $(obj).parent().siblings("td").eq(1).text();
	  var ingImage= $(obj).parent().siblings("td").eq(2).text();  
	  var ingPrice= $(obj).parent().siblings("td").eq(3).text();
	  var ingDetail= $(obj).parent().siblings("td").eq(4).text();
	  var ingStock= $(obj).parent().siblings("td").eq(5).text();
	  var ingStatus= $(obj).parent().siblings("td").eq(6).text();	
	  var ingId=$(obj).siblings("input").eq(0).val();
	  $("#ingName").val(ingName);
	  $("#ingImage").val(ingImage);
	  $("#ingPrice").val(ingPrice);
	  $("#ingDetail").val(ingDetail);
	  $("#ingStock").val(ingStock);
	  $("#ingStatus").val(ingStatus);
	  $("#ingId").val(ingId);
	  alert(ingId);
  }
  function update(){
	  
	 var ingId=$("#ingId").val();    
	  var ingName=$("#ingName").val();
	  var ingPrice=$("#ingPrice").val();
	  var ingDetail=$("#ingDetail").val();
	  var ingStock=$("#ingStock").val();
	  var ingStatus=$("#ingStatus").val();
	  var ingImage=$("#ingName").val();	  
	    $.ajax({
	        type: "post",
	        url: "updateIntegralGoods",
	        data: {'ingId':ingId,'ingName':ingName,'ingPrice':ingPrice,'ingDetail':ingDetail,'ingStock':ingStock,'ingStatus':ingStatus,'ingImage':ingImage},
	        dataType: 'json',
	        async:'true',
	        contentType: "application/x-www-form-urlencoded; charset=utf-8",
	        success: function(result) {
	            //location.reload();
	        }
	    });
	}
$(function(){
	$.ajax({
		url:'loadIntegralGoods',
		dataType:'json',
		type:'post',
		async:'true',
		success:function(result){
			$("#ftable").html('+<colgroup>'+'<col width="100">'+'<col width="200">'+'<col>'+'</colgroup>'+'<tr>'+
		      '<td>商品ID</td>'+
		      '<td>商品名称</td>'+
		      '<td>商品图片</td>'+
		      '<td>商品价格</td>'+
		      '<td>商品详情</td>'+
		      '<td>商品库存</td>'+
		      '<td>商品状态</td>'+
		      '<td>操作</td>'+
		    '</tr>'),
		    $.each(result,function(index,ele){	
		    	var a=ele.ingName;
		    	$("#ftable").append('+<colgroup>'+'<col width="100">'+'<col width="200">'+'<col>'+'</colgroup>'+'<tr>'+		
		  		      '<td>'+(index+1)+'</td>'+
		  		      '<td>'+ele.ingName+'</td>'+
		  		      '<td><img  src="images/'+ele.ingImage+'"></td>'+
		  		      '<td>'+ele.ingPrice+'</td>'+
		  		      '<td>'+ele.ingDetail+'</td>'+
		  		      '<td>'+ele.ingStock+'</td>'+
		  		      '<td>'+ele.ingStatus+'</td>'+
		  		      '<td>'+	
		  		      '<a href="deleteIntegralGoods?ingId='+ele.ingId+'"  class="layui-btn layui-btn-xs " lay-event="edit"><i class="layui-icon">&#xe640;</i>删除</a>'+		  			  		  		
		  		      '<input type="hidden" value="'+ele.ingId+'"/>'+
		  		      '<input  type="button"  onclick="updateData(this)" value="修改" class=" layui-btn layui-btn-danger layui-btn-xs" data-toggle="modal" data-target="#updateIg" lay-event="del">'+
		   		      '<input  type="button"  onclick="addOrder(this)" value="确认" class=" layui-btn layui-btn-danger layui-btn-xs" data-toggle="modal" data-target="#addIo" lay-event="del">'+			     		  		      
		  		      '</td>'+
		  		      '</tr>'				    
		    	)   	
		   })	 		   		    
		}	
	});	
})
</script>
<form action="list" method="post">
<table class="layui-table" id="ftable">  
</table>
</form> 

 <!-- Modal -->
<div class="modal fade" id="addIo" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
   
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">请填写信息</h4>
      </div>
      <div class="modal-body">
      <div class="form-group has-warning">
    <label for="收货地址">收货地址</label>
    <input type="text" class="form-control"  placeholder="收货地址" name="address" id="address">
    </div>
<div class="form-group has-success">
    <label for="姓名">姓名</label>
    <input type="text" class="form-control"  placeholder="姓名" name="rname" id="rname">
    </div>  
<div class="form-group has-success">
    <label for="联系电话">联系电话</label>
    <input type="text" class="form-control"  placeholder="联系电话" name="phone" id="phone">
    </div>           
      
       <div class="form-group has-success">
    <label for="">商品名称</label>
    <input type="text" class="form-control"  placeholder="商品名称" name="ingName"  id="ingName"  readonly >
  </div>
<div class="form-group has-warning">
    <label for="商品价格">商品价格</label>
    <input type="text" class="form-control"  placeholder="商品价格" name="ingPrice" id="ingPrice" readonly>
    </div>
<div class="form-group has-success">
    <label for="商品详情">商品详情</label>
    <input type="text" class="form-control"  placeholder="商品详情" name="ingDetail" id="ingDetail" readonly>
    </div> 

<div class="form-group has-warning" id="uploadForm">
    <label for="商品图片" >商品图片:</label>
    <input type="file" name="ing" id="ingImage" readonly>   
  </div>  	
      </div>
      <div class="modal-footer">
        <button class="layui-btn"  lay-filter="formDemo" data-dismiss="modal">Close</button>   
      	<input type="hidden" name="ingId" id="ingId">  
      	<input type="hidden" name="u_id" id="u_id" value="7">  
        <button type="button" class="layui-btn layui-btn-success" onclick="add()">添加</button>    
      </div>    
    </div>
  </div>
</div>
<!--*=========================================================================================================================================*-->
<!--*=========================================================================================================================================*-->
<!--*=========================================================================================================================================*-->
<!-- Modal -->
<div class="modal fade" id="updateIg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
   
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
       <div class="form-group has-success">
    <label for="商品名称">商品名称</label>
    <input type="text" class="form-control"  placeholder="商品名称" name="ingName"  id="ingName"   >
  </div>
<div class="form-group has-warning">
    <label for="商品价格">商品价格</label>
    <input type="text" class="form-control"  placeholder="商品价格" name="ingPrice" id="ingPrice">
    </div>
<div class="form-group has-success">
    <label for="商品详情">商品详情</label>
    <input type="text" class="form-control"  placeholder="商品详情" name="ingDetail" id="ingDetail">
    </div> 
<div class="form-group has-warning">
    <label for="商品库存">商品库存</label>
    <input type="text" class="form-control"  placeholder="商品库存" name="ingStock" id="ingStock">
    </div>
<div class="form-group has-success">
    <label for="商品状态">商品状态</label>
    <input type="text" class="form-control"  placeholder="商品状态" name="ingStatus" id="ingStatus">
    </div>          
<div class="form-group has-warning" id="uploadForm">
    <label for="商品图片" >商品图片</label>
    <input type="file" name="ing" id="ingImage">   
  </div>  	
      </div>
      <div class="modal-footer">
        <button class="layui-btn"  lay-filter="formDemo" data-dismiss="modal">Close</button>   
      	<input type="hidden" name="ingId" id="ingId">        
        <button type="button" class="layui-btn layui-btn-success" onclick="update()">提交修改</button>    
      </div>    
    </div>
  </div>
</div>
<!--*=========================================================================================================================================*-->
<!--*=========================================================================================================================================*-->
<!--*=========================================================================================================================================*-->

 <form action="addIntegralGoods" method="post" enctype="multipart/form-data">
 <!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  添加商品
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
   
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
       <div class="form-group has-success">
    <label for="商品名称">商品名称</label>
    <input type="text" class="form-control"  placeholder="商品名称" name="ingName"  id="ingName"  >
  </div>
<div class="form-group has-warning">
    <label for="商品价格">商品价格</label>
    <input type="text" class="form-control"  placeholder="商品价格" name="ingPrice" id="ingPrice">
    </div>
<div class="form-group has-success">
    <label for="商品详情">商品详情</label>
    <input type="text" class="form-control"  placeholder="商品详情" name="ingDetail" id="ingDetail">
    </div> 
<div class="form-group has-warning">
    <label for="商品库存">商品库存</label>
    <input type="text" class="form-control"  placeholder="商品库存" name="ingStock" id="ingStock">
    </div>
<div class="form-group has-success">
    <label for="商品状态">商品状态</label>
    <input type="text" class="form-control"  placeholder="商品状态" name="ingStatus" id="ingStatus">
    </div>          
<div class="form-group has-warning">
    <label for="商品图片" >商品图片</label>
    <input type="file" name="ingIm" id="ingImage">
  </div>  	
      </div>
      <div class="modal-footer">
        <button class="layui-btn"  lay-filter="formDemo" data-dismiss="modal">Close</button>     
        <input  type="submit" value="提交" class="layui-btn layui-btn-success" >       
      </div>    
    </div>
  </div>
</div> 
 </form>
 
</body>
</html>